﻿using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using Hotel.Vendor.InterfacePlatformManage.Entity.HTicketEntity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Ctrip.Common.Utility;
using Hotel.Vendor.InterfacePlatformManage.Data.VenderStaticData;
using HTicket.Entity;
using System;

namespace Hotel.Vendor.InterfacePlatformManage.Data.HTicketData
{
    public class HotelInterfaceTaskListProcess
    {

        /// <summary>
        /// 根据EId获取用户相关信息
        /// </summary>
        /// <param name="eID"></param>
        /// <returns></returns>
        public static UserViewModel GetUserInfoByID(string eID)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select U.*,G.GroupName,P.ProjectId,P.ProjectName,P.ProjectType,RE.*,M.*,S.ColumnField,S.ColumnName,S.ColumnWidth from HotelInterface_TaskUserInfo U
                            inner join HotelInterface_TaskGroupInfo G on U.GroupID = G.GroupID
                            inner join HotelInterface_TaskProject P on G.GroupID = P.GroupID
                            inner join HotelInterface_TaskUserRole R on R.EID = U.Eid
                            inner join HotelInterface_TaskRoleRescource RE on RE.RoleID = R.RoleID
                            inner join HotelInterface_TaskRoleMenuInfo RM on RM.RoleID = R.RoleID
                            inner join HotelInterface_TaskMenu M on M.MenuID = RM.MenuID
                            inner join HotelInterface_TaskGridViewSetting S on S.GroupID = G.GroupID
                            where U.Eid = @Eid";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@Eid", DbType.String, eID);

            UserViewModel userInfoViewModel = new UserViewModel();
            HotelInterface_TaskGroupInfo groupInfo = new HotelInterface_TaskGroupInfo();
            List<HotelInterface_TaskRoleRescource> roleRescourceList = new List<Entity.HTicketEntity.HotelInterface_TaskRoleRescource>();
            List<HotelInterface_TaskMenu> menuList = new List<Entity.HTicketEntity.HotelInterface_TaskMenu>();
            List<HotelInterface_TaskGridViewSetting> gridviewList = new List<HotelInterface_TaskGridViewSetting>();
            DataSet ds = db.ExecuteDataSet(dbCommand);
            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    userInfoViewModel.EID = CommonFunc.ConvertObjectToString(idr["EID"]);
                    groupInfo.GroupID = CommonFunc.ConvertObjectToString(idr["GroupID"]);
                    groupInfo.GroupName = CommonFunc.ConvertObjectToString(idr["GroupName"]);
                    userInfoViewModel.GroupInfo = groupInfo;

                    HotelInterface_TaskGridViewSetting gridview = new HotelInterface_TaskGridViewSetting();
                    gridview.ColumnField = CommonFunc.ConvertObjectToString(idr["ColumnField"]);
                    gridview.ColumnName = CommonFunc.ConvertObjectToString(idr["ColumnName"]);
                    gridview.ColumnWidth = CommonFunc.ConvertObjectToInt32(idr["ColumnWidth"]);
                    gridview.GroupID = CommonFunc.ConvertObjectToString(idr["GroupID"]);
                    if (!gridviewList.Exists(x => { return x.ColumnField == gridview.ColumnField; }))
                    {
                        if (!gridview.ColumnField.ToLower().Contains("taskid"))
                        {
                            gridviewList.Add(gridview);
                        }
                    }
                    groupInfo.GridViewSetting = gridviewList;

                    HotelInterface_TaskRoleRescource roleRescource = new HotelInterface_TaskRoleRescource();
                    roleRescource.RoleID = CommonFunc.ConvertObjectToInt32(idr["RoleID"]);
                    roleRescource.RoleName = CommonFunc.ConvertObjectToString(idr["RoleName"]);
                    roleRescource.IsCreate = CommonFunc.ConvertToBool(idr["IsCreate"]);
                    roleRescource.IsEmailRecive = CommonFunc.ConvertToBool(idr["IsEmailReceive"]);
                    roleRescource.IsManager = CommonFunc.ConvertToBool(idr["IsManager"]);
                    roleRescource.IsSubmit = CommonFunc.ConvertToBool(idr["IsSubmit"]);
                    if (!roleRescourceList.Exists(x => { return x.RoleID == roleRescource.RoleID; }))
                    {
                        roleRescourceList.Add(roleRescource);
                    }

                    userInfoViewModel.RoleRescource = roleRescourceList;

                    HotelInterface_TaskMenu menu = new HotelInterface_TaskMenu();
                    menu.MenuID = CommonFunc.ConvertObjectToInt32(idr["MenuID"]);
                    menu.MenuLink = CommonFunc.ConvertObjectToString(idr["MenuLink"]);
                    if (!menuList.Exists(x => { return x.MenuID == menu.MenuID; }))
                    {
                        menuList.Add(menu);
                    }

                    userInfoViewModel.Menu = menuList;
                }
            }

            return userInfoViewModel;
        }

        /// <summary>
        /// 根据groupID得到Group信息
        /// </summary>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public GroupViewModel GetGroupInfoByGroupId(string groupID)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select G.GroupID,G.GroupName,GV.ColumnField,GV.ColumnName,GV.ColumnWidth,Re.IsCreate,Re.IsEmailRecive,Re.IsManager,Re.IsSubmit,Re.RoleID,Re.RoleName,M.MenuID,M.MenuLink
                            from HotelInterface_TaskGroupInfo as G
                            inner join HotelInterface_TaskGroupRole as R on G.GroupID = R.GroupID
                            inner join HotelInterface_TaskRoleRescource as Re on Re.RoleID = R.RoleID
                            inner join HotelInterface_TaskRoleMenuInfo as MI on MI.RoleID = R.RoleID
                            inner join HotelInterface_TaskGridView GV on G.GroupID = GV.GroupID
                            inner join HotelInterface_TaskMenu as M on MI.MenuID = M.MenuID
                            where G.GroupID = @GroupID";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@GroupID", DbType.String, groupID);

            GroupViewModel groupViewModel = new GroupViewModel();
            DataSet ds = db.ExecuteDataSet(dbCommand);
            List<HotelInterface_TaskGridViewSetting> gridviewList = new List<HotelInterface_TaskGridViewSetting>();
            HotelInterface_TaskGroupInfo groupInfo = new HotelInterface_TaskGroupInfo();

            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    groupViewModel.GroupInfo.GroupID = CommonFunc.ConvertObjectToString(idr["GroupID"]);
                    groupViewModel.GroupInfo.GroupName = CommonFunc.ConvertObjectToString(idr["GroupName"]);

                    HotelInterface_TaskGridViewSetting gridview = new HotelInterface_TaskGridViewSetting();
                    gridview.ColumnField = CommonFunc.ConvertObjectToString(idr["ColumnField"]);
                    gridview.ColumnName = CommonFunc.ConvertObjectToString(idr["ColumnName"]);
                    gridview.ColumnWidth = CommonFunc.ConvertObjectToInt32(idr["ColumnWidth"]);
                    gridview.GroupID = CommonFunc.ConvertObjectToString(idr["GroupID"]);
                    gridviewList.Add(gridview);
                    groupInfo.GridViewSetting = gridviewList;

                    HotelInterface_TaskRoleRescource roleRescource = new HotelInterface_TaskRoleRescource();
                    roleRescource.RoleID = CommonFunc.ConvertObjectToInt32(idr["RoleID"]);
                    roleRescource.RoleName = CommonFunc.ConvertObjectToString(idr["RoleName"]);
                    roleRescource.IsCreate = CommonFunc.ConvertToBool(idr["IsCreate"]);
                    roleRescource.IsEmailRecive = CommonFunc.ConvertToBool(idr["IsEmailRecive"]);
                    roleRescource.IsManager = CommonFunc.ConvertToBool(idr["IsManager"]);
                    roleRescource.IsSubmit = CommonFunc.ConvertToBool(idr["IsSubmit"]);
                    groupViewModel.RoleRescource.Add(roleRescource);

                    HotelInterface_TaskMenu menu = new HotelInterface_TaskMenu();
                    menu.MenuID = CommonFunc.ConvertObjectToInt32(idr["MenuID"]);
                    menu.MenuLink = CommonFunc.ConvertObjectToString(idr["MenuLink"]);
                    groupViewModel.Menu.Add(menu);
                }
            }

            return groupViewModel;
        }


        /// <summary>
        /// 根据GroupID获取Project列表
        /// </summary>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public static List<HotelInterface_TaskProject> GetProjectList(string groupID)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select * from HotelInterface_TaskProject
                            where GroupID = GroupID";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@GroupID", DbType.String, groupID);

            List<HotelInterface_TaskProject> projectList = new List<HotelInterface_TaskProject>();

            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    HotelInterface_TaskProject project = new HotelInterface_TaskProject();
                    project.GroupID = CommonFunc.ConvertObjectToString(idr["GroupID"]);
                    project.ProjectID = CommonFunc.ConvertObjectToInt32(idr["ProjectID"]);
                    project.ProjectName = CommonFunc.ConvertObjectToString(idr["ProjectName"]);
                    project.ProjectType = CommonFunc.ConvertObjectToString(idr["ProjectType"]);

                    projectList.Add(project);
                }
            }

            return projectList;
        }


        /// <summary>
        /// 根据GroupID获取Project列表
        /// </summary>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public static List<ChartSet> GetChartList(string groupID,string startTime,string endTime)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select U.UserName,(select count(1) from dbo.HotelInterface_TaskListProcess P where P.handleman = U.Eid  and P.AddTime between '"+startTime+"' and '"+endTime+"') HTickets from dbo.HotelInterface_TaskUserInfo U where U.GroupID = @GroupID";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@GroupID", DbType.String, groupID);

            List<ChartSet> chartSetList = new List<ChartSet>();

            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    ChartSet chartSet = new ChartSet();
                    chartSet.Label = CommonFunc.ConvertObjectToString(idr["UserName"]);
                    chartSet.Value = CommonFunc.ConvertObjectToString(idr["HTickets"]);

                    chartSetList.Add(chartSet);
                }
            }

            return chartSetList;
        }


        /// <summary>
        /// 根据projectID查询相关信息
        /// </summary>
        /// <param name="projectID"></param>
        public static ProjectViewModel GetGroupByProjectID(int projectID)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select P.ProjectID,G.GroupID,G.GroupName,U.Eid,U.RoleID,U.GroupID as UGroupID
                                from HotelInterface_TaskProject as P 
                                inner join  HotelInterface_TaskGroupInfo as G on P.GroupID  = G.GroupID
                                inner join HotelInterface_TaskUserInfo as U on U.GroupID = G.GroupID
                                where P.ProjectID = @ProjectID";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@ProjectID", DbType.String, projectID);

            ProjectViewModel projectViewModel = new ProjectViewModel();
            DataSet ds = db.ExecuteDataSet(dbCommand);
            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {

                    projectViewModel.ProjectInfo.ProjectID = CommonFunc.ConvertObjectToInt32(idr["ProjectID"]);
                    projectViewModel.ProjectInfo.ProjectName = CommonFunc.ConvertObjectToString(idr["ProjectName"]);

                    projectViewModel.GroupInfo.GroupID = CommonFunc.ConvertObjectToString(idr["GroupID"]);
                    projectViewModel.GroupInfo.GroupName = CommonFunc.ConvertObjectToString(idr["GroupName"]);

                    HotelInterface_TaskUserInfo userInfo = new HotelInterface_TaskUserInfo();
                    userInfo.Eid = CommonFunc.ConvertObjectToString(idr["Eid"]);
                    userInfo.GroupID = CommonFunc.ConvertObjectToString(idr["UGroupID"]);
                    userInfo.RoleID = CommonFunc.ConvertObjectToInt32(idr["RoleID"]);
                    projectViewModel.UserInfo.Add(userInfo);
                }
            }

            return projectViewModel;
        }

        /// <summary>
        /// 获取TaskList列表
        /// </summary>
        /// <returns></returns>
        public static List<HotelInterface_TaskListProcess> GetALLTaskList(TaskSearchConditionEntity searchEntity)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            DbCommand dbCommand = db.GetSqlStringCommand(GetTaskListByCondition(searchEntity));

            List<HotelInterface_TaskListProcess> taskListProcessList = new List<HotelInterface_TaskListProcess>();

            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    HotelInterface_TaskListProcess taskListProcess = new HotelInterface_TaskListProcess();
                    taskListProcess.TaskID = CommonFunc.ConvertObjectToInt32(idr["TaskID"]);
                    taskListProcess.AddTime = CommonFunc.ConvertObjectToString(idr["AddTime"]);
                    taskListProcess.EID = CommonFunc.ConvertObjectToString(idr["EID"]);
                    taskListProcess.HandleEndTime = CommonFunc.ConvertObjectToString(idr["HandleEndTime"]);
                    taskListProcess.HandleMan = CommonFunc.ConvertObjectToString(idr["HandleMan"]);
                    taskListProcess.HandleStartTime = CommonFunc.ConvertObjectToString(idr["HandleStartTime"]);
                    taskListProcess.HopeTime = CommonFunc.ConvertObjectToString(idr["HopeTime"]);
                    taskListProcess.Importance = CommonFunc.ConvertObjectToString(idr["Importance"]);
                    taskListProcess.ProjectId = CommonFunc.ConvertObjectToInt32(idr["ProjectId"]);
                    taskListProcess.State = Enum.GetName(typeof(StateEnum), idr["State"]);
                    taskListProcess.Subject = GetShortTitle(CommonFunc.ConvertObjectToString(idr["Subject"]), 35);
                    taskListProcess.Timepass = CommonFunc.ConvertObjectToString(idr["Timepass"]);
                    taskListProcess.ProjectName = CommonFunc.ConvertObjectToString(idr["ProjectName"]);
                    taskListProcess.ProjectType = CommonFunc.ConvertObjectToString(idr["ProjectType"]);

                    taskListProcessList.Add(taskListProcess);
                }
            }

            return taskListProcessList;
        }

        /// <summary>
        /// 返回修改的字符
        /// </summary>
        /// <param name="title"></param>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetShortTitle(string title, int length)
        {
            if (title.Length < length)
            {
                return title.Substring(0, title.Length);
            }
            else
            {
                return title.Substring(0, length) + "...";
            }
        }

        /// <summary>
        /// 通过TaskID获取Task信息
        /// </summary>
        /// <param name="taskID"></param>
        /// <returns></returns>
        public static HotelInterface_TaskListProcess GetTaskListByTaskID(string taskID)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select * from dbo.HotelInterface_TaskListProcess
                           where TaskID =@TaskID";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@TaskID", DbType.String, taskID);

            HotelInterface_TaskListProcess taskListProces = new HotelInterface_TaskListProcess();

            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    taskListProces.TaskID = CommonFunc.ConvertObjectToInt32(idr["TaskID"]);
                    taskListProces.AddTime = CommonFunc.ConvertObjectToString(idr["AddTime"]);
                    taskListProces.EID = CommonFunc.ConvertObjectToString(idr["EID"]);
                    taskListProces.HandleEndTime = CommonFunc.ConvertObjectToString(idr["HandleEndTime"]);
                    taskListProces.HandleMan = CommonFunc.ConvertObjectToString(idr["HandleMan"]);
                    taskListProces.HandleStartTime = CommonFunc.ConvertObjectToString(idr["HandleStartTime"]);
                    taskListProces.HopeTime = CommonFunc.ConvertObjectToString(idr["HopeTime"]);
                    taskListProces.Importance = CommonFunc.ConvertObjectToString(idr["Importance"]);
                    taskListProces.ProjectId = CommonFunc.ConvertObjectToInt32(idr["ProjectId"]);
                    taskListProces.State = CommonFunc.ConvertObjectToString(idr["State"]);
                    taskListProces.Subject = CommonFunc.ConvertObjectToString(idr["Subject"]);
                    taskListProces.Timepass = CommonFunc.ConvertObjectToString(idr["Timepass"]);
                }
            }

            return taskListProces;
        }

        /// <summary>
        /// 获取TaskList列表
        /// </summary>
        /// <returns></returns>
        public static int GetALLTaskListCountByGroupID(string groupID)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select Count(1) from HotelInterface_TaskListProcess P
                            inner join HotelInterface_TaskProject T on T.ProjectId = P.ProjectId
                            where GroupID=@GroupID";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@GroupID", DbType.String, groupID);
            object count = db.ExecuteScalar(dbCommand);

            if (count != null)
            {
                return Convert.ToInt32(count);
            }

            return 0;
        }

        /// <summary>
        /// 根据TaskID得到Task信息
        /// </summary>
        /// <param name="taskID"></param>
        /// <returns></returns>
        public static List<HotelInterfaceTaskListProcessContentEntity> GeTaskContentByTaskID(TaskSearchConditionEntity searchEntity)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select G.*,P.[state],P.Importance,P.HopeTime,P.[Subject],P.ProjectId,T.ProjectName 
                            from HotelInterfaceLogDB..HotelInterface_TaskListProcessContentLog G
                            inner join HotelInterface_TaskListProcess P on G.TaskID = P.TaskID
                            inner join HotelInterface_TaskProject T on T.ProjectID = P.ProjectId
                            where  P.TaskID=@TaskID
                            order by DataChange_LastTime desc";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@TaskID", DbType.String, searchEntity.TaskID);
            DataSet ds = db.ExecuteDataSet(dbCommand);

            List<HotelInterfaceTaskListProcessContentEntity> contentList = new List<HotelInterfaceTaskListProcessContentEntity>();

            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    HotelInterfaceTaskListProcessContentEntity taskListProcess = new HotelInterfaceTaskListProcessContentEntity();
                    taskListProcess.Content = CommonFunc.ConvertObjectToString(idr["Content"]);
                    taskListProcess.Eid = CommonFunc.ConvertObjectToString(idr["Eid"]);
                    taskListProcess.Flag = CommonFunc.ConvertObjectToString(idr["Flag"]);
                    taskListProcess.TaskID = CommonFunc.ConvertObjectToInt32(idr["TaskID"]);
                    taskListProcess.DataChange_LastTime = CommonFunc.ConvertObjectToString(idr["DataChange_LastTime"]);
                    taskListProcess.State = CommonFunc.ConvertObjectToString(idr["State"]);
                    taskListProcess.Importance = CommonFunc.ConvertObjectToString(idr["Importance"]);
                    taskListProcess.HopeTime = CommonFunc.ConvertObjectToString(idr["HopeTime"]);
                    taskListProcess.Subject = CommonFunc.ConvertObjectToString(idr["Subject"]);
                    taskListProcess.ProjectID = CommonFunc.ConvertObjectToInt32(idr["ProjectID"]);
                    taskListProcess.ProjectName = CommonFunc.ConvertObjectToString(idr["ProjectName"]);
                    contentList.Add(taskListProcess);
                }
            }

            return contentList;
        }

        /// <summary>
        /// 根据条件获取TaskList sql 语句
        /// </summary>
        /// <param name="searchEntity"></param>
        /// <returns></returns>
        private static string GetTaskListByCondition(TaskSearchConditionEntity searchEntity)
        {

            StringBuilder sd = new StringBuilder("select row_number() over(order by TaskID desc) as number,T.*,P.GroupID,P.ProjectName,P.ProjectType from dbo.HotelInterface_TaskListProcess T inner join HotelInterface_TaskProject P on P.ProjectId = T.ProjectId where GroupID ='" + searchEntity.GroupID + "' ");

            if (!string.IsNullOrEmpty(searchEntity.AddTime))
            {
                sd.Append(" and AddTime='" + searchEntity.AddTime + "'");
            }
            else if (!string.IsNullOrEmpty(searchEntity.Eid))
            {
                sd.Append(" and Eid='" + searchEntity.Eid + "'");
            }
            else if (!string.IsNullOrEmpty(searchEntity.HandleMan))
            {
                sd.Append(" and HandleMan like'%" + searchEntity.HandleMan + "%'");
            }
            else if (!string.IsNullOrEmpty(searchEntity.Improtance))
            {
                sd.Append(" and Improtance='" + searchEntity.Improtance + "'");
            }
            else if (!string.IsNullOrEmpty(searchEntity.ProjectName))
            {
                sd.Append(" and ProjectName like '%" + searchEntity.ProjectName + "%'");
            }
            else if (!string.IsNullOrEmpty(searchEntity.State))
            {
                sd.Append(" and State like '%" + searchEntity.State + "%'");
            }
            else if (!string.IsNullOrEmpty(searchEntity.Subject))
            {
                sd.Append(" and Subject like '%" + searchEntity.Subject + "%'");
            }
            else if (!string.IsNullOrEmpty(searchEntity.TaskID))
            {
                sd.Append(" and TaskID='" + searchEntity.TaskID + "'");
            }

            return string.Format("select * from ({0}) as M where number > '" + (searchEntity.Index - 1) * searchEntity.PageSize + "' and number < = '" + searchEntity.Index * searchEntity.PageSize + "'", sd.ToString());
        }


        #region HotelInterface_TaskListProcess

        /// <summary>
        /// 新增Task
        /// </summary>
        /// <param name="id"></param>
        /// <param name="xmlConfig"></param>
        /// <returns></returns>
        public static string InsertTaskListProcess(HotelInterface_TaskListProcess taskEntity)
        {
            string taskID = string.Empty;
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select * from dbo.HotelInterface_TaskUserInfo
                                where GroupID =@GroupID
                                order by ParentID";
            DbCommand dbcommand = db.GetStoredProcCommand("sp3_HotelInterface_TaskListProcess_i");
            db.AddOutParameter(dbcommand, "@TaskID", DbType.Int32, 0);
            db.AddInParameter(dbcommand, "@AddTime", DbType.String, taskEntity.AddTime);
            db.AddInParameter(dbcommand, "@EID", DbType.String, taskEntity.EID);
            db.AddInParameter(dbcommand, "@HandleEndTime", DbType.String, taskEntity.HandleEndTime);
            db.AddInParameter(dbcommand, "@HandleMan", DbType.String, taskEntity.HandleMan);
            db.AddInParameter(dbcommand, "@HandleStartTime", DbType.String, taskEntity.HandleStartTime);
            db.AddInParameter(dbcommand, "@HopeTime", DbType.String, taskEntity.HopeTime);
            db.AddInParameter(dbcommand, "@Importance", DbType.String, taskEntity.Importance);
            db.AddInParameter(dbcommand, "@ProjectId", DbType.String, taskEntity.ProjectId);
            db.AddInParameter(dbcommand, "@State", DbType.String, taskEntity.State);
            db.AddInParameter(dbcommand, "@Subject", DbType.String, taskEntity.Subject);
            db.AddInParameter(dbcommand, "@Timepass", DbType.String, taskEntity.Timepass);

            db.ExecuteNonQuery(dbcommand);

            taskID = db.GetParameterValue(dbcommand, "@TaskID").ToString();
            return taskID;
        }

        /// <summary>
        /// 更新Task
        /// </summary>
        /// <param name="id"></param>
        /// <param name="xmlConfig"></param>
        /// <returns></returns>
        public static bool UpdateHotelInterface_TaskListProcess(HotelInterface_TaskListProcess taskEntity)
        {
            try
            {
                IList<Parameter> paramList = new List<Parameter>();
                paramList.Add(DBHelper.CreateInParamter("@HandleMan", DbType.String, taskEntity.HandleMan));
                paramList.Add(DBHelper.CreateInParamter("@Importance", DbType.String, taskEntity.Importance));
                paramList.Add(DBHelper.CreateInParamter("@State", DbType.String, taskEntity.State));
                paramList.Add(DBHelper.CreateInParamter("@TaskID", DbType.String, taskEntity.TaskID));
                DBHelper.ExecuteProc("sp3_HotelInterface_TaskListProcess_u", "HotelInterfaceDB_SELECT", paramList);
            }
            catch (System.Exception)
            {
                return false;
            }

            return true;
        }

        #endregion

        #region HotelInterface_TaskListProcessContentLog

        /// <summary>
        /// 新增TaskContent
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void InsertTaskListProcessContentLog(HotelInterfaceTaskListProcessContentEntity taskContentEntity)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@TaskListProcessContentLogID", DbType.String, "0"));
            paramList.Add(DBHelper.CreateInParamter("@Content", DbType.String, taskContentEntity.Content));
            paramList.Add(DBHelper.CreateInParamter("@Eid", DbType.String, taskContentEntity.Eid));
            paramList.Add(DBHelper.CreateInParamter("@Flag", DbType.String, taskContentEntity.Flag));
            paramList.Add(DBHelper.CreateInParamter("@TaskID", DbType.String, taskContentEntity.TaskID));
            paramList.Add(DBHelper.CreateInParamter("@DataChange_LastTime", DbType.String, taskContentEntity.DataChange_LastTime));
            DBHelper.ExecuteProc("sp3_HotelInterface_TaskListProcessContentLog_i", "HotelInterfaceLogDB_SELECT", paramList);
        }

        /// <summary>
        /// 更新TaskContent
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void UpdateTaskListProcessContentLog(HotelInterfaceTaskListProcessContentEntity taskContentEntity)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@Content", DbType.String, taskContentEntity.Content));
            paramList.Add(DBHelper.CreateInParamter("@Eid", DbType.String, taskContentEntity.Eid));
            paramList.Add(DBHelper.CreateInParamter("@Flag", DbType.String, taskContentEntity.Flag));
            paramList.Add(DBHelper.CreateInParamter("@TaskID", DbType.String, taskContentEntity.TaskID));
            paramList.Add(DBHelper.CreateInParamter("@DataChange_LastTime", DbType.String, taskContentEntity.DataChange_LastTime));
            DBHelper.ExecuteProc("sp3_HotelInterface_TaskListProcessContentLog_u", "HotelInterfaceDB_SELECT", paramList);
        }

        #endregion

        #region HotelInterface_TaskUserInfo


        /// <summary>
        /// 根据GroupID获取用户信息
        /// </summary>
        /// <param name="groupID"></param>
        /// <returns></returns>
        public static List<HotelInterface_TaskUserInfo> GetUserInfoByGroupId(string groupID)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select * from dbo.HotelInterface_TaskUserInfo
                                where GroupID =@GroupID
                                order by ParentID";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@GroupID", DbType.String, groupID);

            List<HotelInterface_TaskUserInfo> userInfoList = new List<HotelInterface_TaskUserInfo>();

            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    HotelInterface_TaskUserInfo userInfo = new HotelInterface_TaskUserInfo();
                    userInfo.Eid = CommonFunc.ConvertObjectToString(idr["Eid"]);
                    userInfo.GroupID = CommonFunc.ConvertObjectToString(idr["GroupID"]);
                    userInfo.ParentID = CommonFunc.ConvertObjectToString(idr["ParentID"]);
                    userInfo.Email = CommonFunc.ConvertObjectToString(idr["Email"]);
                    userInfo.UserName = CommonFunc.ConvertObjectToString(idr["UserName"]);

                    userInfoList.Add(userInfo);
                }
            }

            return userInfoList;
        }

        /// <summary>
        /// 新增UserInfo
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void InsertUserInfo(HotelInterface_TaskUserInfo userInfo)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@Eid", DbType.String, userInfo.Eid));
            paramList.Add(DBHelper.CreateInParamter("@GroupID", DbType.String, userInfo.GroupID));
            paramList.Add(DBHelper.CreateInParamter("@RoleID", DbType.String, userInfo.RoleID));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskUserInfo_Add", "HotelInterfaceDB_SELECT", paramList);
        }

        /// <summary>
        /// 更新UserInfo
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void UpdateUserInfo(HotelInterface_TaskUserInfo userInfo)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@Eid", DbType.String, userInfo.Eid));
            paramList.Add(DBHelper.CreateInParamter("@GroupID", DbType.String, userInfo.GroupID));
            paramList.Add(DBHelper.CreateInParamter("@RoleID", DbType.String, userInfo.RoleID));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskUserInfo_Update", "HotelInterfaceDB_SELECT", paramList);
        }

        #endregion

        #region HotelInterface_TaskGroupInfo
        /// <summary>
        /// 新增GroupInfo
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void InsertGroupInfo(HotelInterface_TaskGroupInfo groupInfo)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@GroupID", DbType.String, groupInfo.GroupID));
            paramList.Add(DBHelper.CreateInParamter("@GroupName", DbType.String, groupInfo.GroupName));
            paramList.Add(DBHelper.CreateInParamter("@GridViewSetting", DbType.String, groupInfo.GridViewSetting));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskGroupInfo_Add", "HotelInterfaceDB_SELECT", paramList);
        }

        /// <summary>
        /// 更新GroupInfo
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void UpdateGroupInfo(HotelInterface_TaskGroupInfo groupInfo)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@GroupID", DbType.String, groupInfo.GroupID));
            paramList.Add(DBHelper.CreateInParamter("@GroupName", DbType.String, groupInfo.GroupName));
            paramList.Add(DBHelper.CreateInParamter("@GridViewSetting", DbType.String, groupInfo.GridViewSetting));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskGroupInfo_Update", "HotelInterfaceDB_SELECT", paramList);
        }

        #endregion

        #region HotelInterface_TaskGroupRole

        ///// <summary>
        ///// 新增GroupRole
        ///// </summary>
        ///// <param name="taskContentEntity"></param>
        //public static void InsertGroupRole(HotelInterface_TaskGroupRole groupRole)
        //{
        //    IList<Parameter> paramList = new List<Parameter>();
        //    paramList.Add(DBHelper.CreateInParamter("@GroupID", DbType.String, groupRole.GroupID));
        //    paramList.Add(DBHelper.CreateInParamter("@RoleID", DbType.String, groupRole.RoleID));
        //    DBHelper.ExecuteProc("sp1_HotelInterface_TaskGroupRole_Add", "HotelInterfaceDB_SELECT", paramList);
        //}

        ///// <summary>
        ///// 更新GroupRole
        ///// </summary>
        ///// <param name="taskContentEntity"></param>
        //public static void UpdateGroupRole(HotelInterface_TaskGroupRole groupRole)
        //{
        //    IList<Parameter> paramList = new List<Parameter>();
        //    paramList.Add(DBHelper.CreateInParamter("@GroupID", DbType.String, groupRole.GroupID));
        //    paramList.Add(DBHelper.CreateInParamter("@RoleID", DbType.String, groupRole.RoleID));
        //    DBHelper.ExecuteProc("sp1_HotelInterface_TaskGroupRole_Update", "HotelInterfaceDB_SELECT", paramList);
        //}

        #endregion

        #region HotelInterface_TaskRoleRescource

        /// <summary>
        /// 根据ProjectID查询EmailReceive
        /// </summary>
        /// <param name="projectID"></param>
        /// <returns></returns>
        public static List<HotelInterface_TaskRoleRescource> GetRoleResourceByProjectID(string projectID)
        {
            Database db = DatabaseFactory.CreateDatabase("HotelInterfaceDB_SELECT");
            string sql = @"select distinct U.Eid,RE.* from HotelInterface_TaskProject T 
                                inner join HotelInterface_TaskGroupInfo G on T.GroupID = G.GroupID
                                inner join HotelInterface_TaskUserInfo U on G.GroupID = U.GroupID
                                inner join HotelInterface_TaskUserRole R on R.EID = U.Eid
                                inner join HotelInterface_TaskRoleRescource RE on RE.RoleID = R.RoleID
                                where ProjectId = @ProjectId";
            DbCommand dbCommand = db.GetSqlStringCommand(sql);
            db.AddInParameter(dbCommand, "@projectID", DbType.String, projectID);
            List<HotelInterface_TaskRoleRescource> list = new List<HotelInterface_TaskRoleRescource>();

            using (IDataReader idr = db.ExecuteReader(dbCommand))
            {
                while (idr.Read())
                {
                    HotelInterface_TaskRoleRescource rolResource = new HotelInterface_TaskRoleRescource();
                    rolResource.EId = CommonFunc.ConvertObjectToString(idr["EId"]);
                    rolResource.IsCreate = CommonFunc.ConvertToBool(idr["IsCreate"]);
                    rolResource.IsEmailRecive = CommonFunc.ConvertToBool(idr["IsEmailReceive"]);
                    rolResource.IsManager = CommonFunc.ConvertToBool(idr["IsManager"]);
                    rolResource.IsSubmit = CommonFunc.ConvertToBool(idr["IsSubmit"]);
                    rolResource.RoleID = CommonFunc.ConvertObjectToInt32(idr["RoleID"]);
                    rolResource.RoleName = CommonFunc.ConvertObjectToString(idr["RoleName"]);

                    list.Add(rolResource);
                }
            }

            return list;
        }

        /// <summary>
        /// 新增RoleRescource
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void InsertRoleRescource(HotelInterface_TaskRoleRescource roleRescource)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@IsCreate", DbType.String, roleRescource.IsCreate));
            paramList.Add(DBHelper.CreateInParamter("@IsEmailRecive", DbType.String, roleRescource.IsEmailRecive));
            paramList.Add(DBHelper.CreateInParamter("@IsManager", DbType.String, roleRescource.IsManager));
            paramList.Add(DBHelper.CreateInParamter("@IsSubmit", DbType.String, roleRescource.IsSubmit));
            paramList.Add(DBHelper.CreateInParamter("@RoleID", DbType.String, roleRescource.RoleID));
            paramList.Add(DBHelper.CreateInParamter("@RoleName", DbType.String, roleRescource.RoleName));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskRoleRescource_Add", "HotelInterfaceDB_SELECT", paramList);
        }

        /// <summary>
        /// 更新RoleRescource
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void UpdateRoleRescource(HotelInterface_TaskRoleRescource roleRescource)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@IsCreate", DbType.String, roleRescource.IsCreate));
            paramList.Add(DBHelper.CreateInParamter("@IsEmailRecive", DbType.String, roleRescource.IsEmailRecive));
            paramList.Add(DBHelper.CreateInParamter("@IsManager", DbType.String, roleRescource.IsManager));
            paramList.Add(DBHelper.CreateInParamter("@IsSubmit", DbType.String, roleRescource.IsSubmit));
            paramList.Add(DBHelper.CreateInParamter("@RoleID", DbType.String, roleRescource.RoleID));
            paramList.Add(DBHelper.CreateInParamter("@RoleName", DbType.String, roleRescource.RoleName));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskRoleRescource_Update", "HotelInterfaceDB_SELECT", paramList);
        }

        #endregion

        #region HotelInterface_TaskRoleMenuInfo
        /// <summary>
        /// 新增RoleMenuInfo
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void InsertRoleMenuInfo(HotelInterface_TaskRoleMenuInfo roleMenuInfo)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@MenuID", DbType.String, roleMenuInfo.MenuID));
            paramList.Add(DBHelper.CreateInParamter("@RoleID", DbType.String, roleMenuInfo.RoleID));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskRoleMenuInfo_Add", "HotelInterfaceDB_SELECT", paramList);
        }

        /// <summary>
        /// 更新RoleMenuInfo
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void UpdateRoleMenuInfo(HotelInterface_TaskRoleMenuInfo roleMenuInfo)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@MenuID", DbType.String, roleMenuInfo.MenuID));
            paramList.Add(DBHelper.CreateInParamter("@RoleID", DbType.String, roleMenuInfo.RoleID));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskRoleMenuInfo_Update", "HotelInterfaceDB_SELECT", paramList);
        }

        #endregion

        #region HotelInterface_TaskMenu

        /// <summary>
        /// 新增RoleMenu
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void InsertMenu(HotelInterface_TaskMenu menu)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@MenuID", DbType.String, menu.MenuID));
            paramList.Add(DBHelper.CreateInParamter("@MenuLink", DbType.String, menu.MenuLink));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskMenu_Add", "HotelInterfaceDB_SELECT", paramList);
        }

        /// <summary>
        /// 更新RoleMenu
        /// </summary>
        /// <param name="taskContentEntity"></param>
        public static void UpdateMenu(HotelInterface_TaskMenu menu)
        {
            IList<Parameter> paramList = new List<Parameter>();
            paramList.Add(DBHelper.CreateInParamter("@MenuID", DbType.String, menu.MenuID));
            paramList.Add(DBHelper.CreateInParamter("@MenuLink", DbType.String, menu.MenuLink));
            DBHelper.ExecuteProc("sp1_HotelInterface_TaskMenu_Update", "HotelInterfaceDB_SELECT", paramList);
        }

        #endregion
    }
}
